<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
  <title>Ubiquity Web Search Commands for Japanese, nora - jgoogle</title>
</head>
<body>
<p>This xhtml source contains commands for searching the Web.  Its
corresponding feed is <a href="ubiquity-commands-ja-nora-jgoogle.html">here</a>.</p>

<div id="jgoogle-news" style="display: none;">
    <style>body{overflow-x:hidden;}</style>
    Google News で <b>${query}</b> を検索:
    <span style="font-size:xx-small;">${resultsstats}</span>
    <div class="items" style="font-size:90%;">
        {for item in items}
            <div id="item${item.key}" class="item" style="border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:4px 0px 0px 0px;padding:0px;box-shadow:2px 2px 2px black;">
                <div id="itemtitle${item.key}" class="itemtitle" style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;">
                    <a href="${item.url}" accesskey="${item.key}" class="itemhref"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;text-decoration:underline;" class="accesskey">${item.key}</span><span style="font-weight:bold;" class="itemtitletext">${item.title}</span></a>
                    <span style="font-size:70%;">${item.sourcemedia}</span>
                </div>
                {if item.photo}
                    <div id="itemimg${item.key}" class="itemimg" style="float:right;margin:1px 1px 1px 4px; font-size: 70%;">${item.photo}</div>
                {/if}
                <div id="itemdesc${item.key}" class="itemdesc" style="margin-left: 4px; font-size: 85%;">${item.description}</div>
                <div class="itemclear" style="clear:both;"> </div>
            </div>
        {forelse}
            <b>該当項目が見つかりませんでした</b>
        {/for}
    </div>
    <div class="bottom" style="position:absolute;bottom:11px;right:0px;height:13px;width:100%;padding:0px;margin:0px;background:rgba(40,40,40,0.7);">
        <div class="note" style="font-size:70%;clear:both;float:left;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
        <div class="navigation" style="font-size:70%;float:right;margin: 0px 5px 0px 0px;">
            <a id="prev" accesskey="8"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">&lt;Prev(<u>8</u>)</span></a>
            Page <span id="page">${page}</span>
            <a id="next" accesskey="9"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">Next(<u>9</u>)&gt;</span></a>
        </div>
    </div>
</div>

<div id="jgoogle-web" style="display: none;">
    <style>body{overflow-x:hidden;}</style>
    Google で <b>${query}</b> を検索:
    <div class="items" style="font-size:90%;">
        {for item in items}
            <div id="item${item.key}" class="item" style="border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:4px 0px 0px 0px;padding:0px;box-shadow:2px 2px 2px black;">
                <div id="itemtitle${item.key}" class="itemtitle" style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;">
                    <a href="${item.url}" accesskey="${item.key}" class="itemhref"><span class="accesskey" style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;text-decoration:underline;">${item.key}</span><span class="itemtitletext" style="font-weight:bold;">${item.title}</span></a>
                </div>
                <div id="itemimg${item.key}" class="itemimg" style="float:left;margin:2px 3px 2px 2px; font-size: 70%;"><a href="${item.url}" class="itemimghref"><img src="http://open.thumbshots.org/image.aspx?url=${item.url}" width="72" height="54" style="border:0px;" /></a></div>
                <div id="itemdesc${item.key}" class="itemdesc" style="margin-left: 4px; font-size: 85%;">
                    ${item.description}
                    <span style="color:green;">${item.visibleUrl}</span>
                    <span class="cachelink"><a href="${item.cacheUrl}" style="color:#77c;">キャッシュ</a></span>
                </div>
                <div class="itemclear" style="clear:both;"> </div>
            </div>
        {forelse}
            <b>該当項目が見つかりませんでした</b>
        {/for}
    </div>
    <div class="bottom" style="position:absolute;bottom:11px;right:0px;height:13px;width:100%;padding:0px;margin:0px;background:rgba(40,40,40,0.7);">
        <div class="note" style="font-size:70%;clear:both;float:left;">※[Ctrl]+[Alt]+[番号] でジャンプ
            <span style="font-size:90%;">(60件/12ページまで表示)</span>
        </div>
        <div class="navigation" style="font-size:70%;float:right;margin: 0px 5px 0px 0px;">
            <a id="prev" accesskey="8"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">&lt;Prev(<u>8</u>)</span></a>
            Page <span id="page">${page}</span>
            <a id="next" accesskey="9"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">Next(<u>9</u>)&gt;</span></a>
        </div>
    </div>
</div>


<div id="jgoogle-image" style="display: none;">
    <style>body{overflow-x:hidden;}</style>
    <b>${query}</b> の Google 画像検索:
    <div class="items" style="font-size:90%;">
        {for item in items}
            <div id="item${item.key}" class="item" style="float:left;margin:3px 0px 0px 0px;padding:0px;-moz-box-shadow:2px 2px 2px black;">
                <div class="itemthumbbox" style="font-size:xx-small;">
                    <a href="http://images.google.co.jp/imgres?imgurl=${item.escapedurl}&amp;imgrefurl=${item.refurl}&amp;hl=ja" accesskey="${item.key}" class="itemhref" style="color:#333333;">
                    <div id="itemthumb${item.key}" class="itemthumbframe" style="border-top:0px;border-right: 2px solid #222;border-bottom: 2px solid #222; border-left: 0px;padding:0px;float:left;margin:0px;-moz-border-radius:2px;"><img src="${item.tburl}" width="${item.thumbw}" height="${item.thumbh}" style="border-top:0px;border-right: 2px solid black;border-bottom: 2px solid black; border-left: 0px;margin:0px;-moz-border-radius:2px;" class="itemthumb" /></div>
                    <span id="itemkey${item.key}" class="accesskey" style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;text-decoration:underline;position:relative;top:5px;left:-20px;">${item.key}</span></a>
                </div>
                <div style="clear:both;width:${item.thumbw}px;">
                    <span id="itemtext${item.key}" class="itemtext" style="margin-left: 4px; font-size: 85%;">
                        <span class="itemsnip">${item.snippet}</span>
                        <span class="itemdesc" style="font-size:80%;">${item.width} x ${item.height}</span>
                        <span class="itemvurl" style="color:green;">${item.visibleurl}</span>
                    </span>
                </div>
                <div class="itemclear" style="clear:both;"> </div>
            </div>
            {if item.key == 4}
            <div class="itemclear" style="clear:both;"> </div>
            {/if}
        {forelse}
            <b>該当項目が見つかりませんでした</b>
        {/for}
    </div>
    <div class="bottom" style="position:absolute;bottom:11px;right:0px;height:13px;width:100%;padding:0px;margin:0px;background:rgba(40,40,40,0.7);">
        <div class="note" style="font-size:70%;clear:both;float:left;">※[Ctrl]+[Alt]+[番号] でジャンプ
            <span style="font-size:90%;">(63件/9ページまで表示)</span>
        </div>
        <div class="navigation" style="font-size:70%;float:right;margin: 0px 5px 0px 0px;">
            <a id="prev" accesskey="8"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">&lt;Prev(<u>8</u>)</span></a>
            Page <span id="page">${page}</span>
            <a id="next" accesskey="9"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">Next(<u>9</u>)&gt;</span></a>
        </div>
    </div>
</div>

<div id="jgoogle-video" style="display: none;">
    <style>body{overflow-x:hidden;}</style>
    <b>${query}</b> の Google 動画検索:
    <div class="items" style="font-size:90%;">
        {for item in items}
            <div id="item${item.key}" class="item" style="float:left;margin:3px 0px 0px 0px;padding:0px;-moz-box-shadow:2px 2px 2px black;">
                <div class="itemthumbbox" style="font-size:xx-small;">
                    <a href="${item.url}" accesskey="${item.key}" class="itemhref" style="color:#333333;">
                    <div id="itemthumb${item.key}" class="itemthumbframe" style="border-top:0px;border-right: 2px solid #222;border-bottom: 2px solid #222; border-left: 0px;padding:0px;float:left;margin:0px;-moz-border-radius:2px;"><img src="${item.tburl}" width="${item.thumbw}" height="${item.thumbh}" style="border-top:0px;border-right: 2px solid black;border-bottom: 2px solid black; border-left: 0px;margin:0px;-moz-border-radius:2px;" class="itemthumb" /></div>
                    <span id="itemkey${item.key}" class="accesskey" style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;text-decoration:underline;position:relative;top:5px;left:-20px;">${item.key}</span></a>
                </div>
                <div style="clear:both;width:${item.thumbw}px;">
                    <span id="itemtext${item.key}" class="itemtext" style="margin-left: 4px; font-size: 85%;">
                        <span class="itemtitle">${item.title}</span>
                        <span class="itemvurl" style="color:green;">${item.visibleurl}</span>
                        <span class="itemsnip">${item.snippet}</span>
                    </span>
                </div>
                <div class="itemclear" style="clear:both;"> </div>
            </div>
            {if item.key == 4}
            <div class="itemclear" style="clear:both;"> </div>
            {/if}
        {forelse}
            <b>該当項目が見つかりませんでした</b>
        {/for}
    </div>
    <div class="bottom" style="position:absolute;bottom:11px;right:0px;height:13px;width:100%;padding:0px;margin:0px;background:rgba(40,40,40,0.7);">
        <div class="note" style="font-size:70%;clear:both;float:left;">※[Ctrl]+[Alt]+[番号] でジャンプ
            <span style="font-size:90%;">(63件/9ページまで表示)</span>
        </div>
        <div class="navigation" style="font-size:70%;float:right;margin: 0px 5px 0px 0px;">
            <a id="prev" accesskey="8"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">&lt;Prev(<u>8</u>)</span></a>
            Page <span id="page">${page}</span>
            <a id="next" accesskey="9"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">Next(<u>9</u>)&gt;</span></a>
        </div>
    </div>
</div>

<div id="jgoogle-picasa" style="display: none;">
    <style>body{overflow-x:hidden;}</style>
    <b>${query}</b> の Picasa 公開画像検索:
    <span id="resultsnum" style="font-size:xx-small;">${totalResults}件<span id="resultsscope">中 ${page*7-6}-${lastItemNumInPage}</span></span>
    <div class="items" style="font-size:90%;">
        {for item in items}
            <div id="item${item.key}" class="item" style="float:left;margin:3px 0px 0px 0px;padding:0px;-moz-box-shadow:2px 2px 2px black;">
                <div class="itemthumbbox" style="font-size:xx-small;">
                    <a href="${item.url}" accesskey="${item.key}" class="itemhref" style="color:#333333;">
                    <div id="itemthumb${item.key}" class="itemthumbframe" style="border-top:0px;border-right: 2px solid #222;border-bottom: 2px solid #222; border-left: 0px;padding:0px;float:left;margin:0px;-moz-border-radius:2px;"><img src="${item.tburl}" width="${item.thumbw}" height="${item.thumbh}" style="border-top:0px;border-right: 2px solid black;border-bottom: 2px solid black; border-left: 0px;margin:0px;-moz-border-radius:2px;" class="itemthumb" /></div>
                    <span id="itemkey${item.key}" class="accesskey" style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;text-decoration:underline;position:relative;top:5px;left:-20px;">${item.key}</span></a>
                </div>
                <div style="clear:both;width:${item.thumbw}px;">
                    <span id="itemtext${item.key}" class="itemtext" style="margin-left: 4px; font-size: 85%;">
                        <span class="itemtitle">${item.title}</span>
                        <span class="itemauthorurl"><a href="${item.authorUrl}" style="color:green !important;">${item.author}</a></span>
                        <span class="itemsnip" style="color:#aaaaaa;">${item.snippet}</span>
                    </span>
                </div>
                <div class="itemclear" style="clear:both;"> </div>
            </div>
            {if item.key == 4}
            <div class="itemclear" style="clear:both;"> </div>
            {/if}
        {forelse}
            <b>該当項目が見つかりませんでした</b>
        {/for}
    </div>
    <div class="bottom" style="position:absolute;bottom:11px;right:0px;height:13px;width:100%;padding:0px;margin:0px;background:rgba(40,40,40,0.7);">
        <div class="note" style="font-size:70%;clear:both;float:left;">※[Ctrl]+[Alt]+[番号] でジャンプ
        </div>
        <div class="navigation" style="font-size:70%;float:right;margin: 0px 5px 0px 0px;">
            <a id="prev" accesskey="8"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">&lt;Prev(<u>8</u>)</span></a>
            Page <span id="page">${page}</span>
            <a id="next" accesskey="9"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">Next(<u>9</u>)&gt;</span></a>
        </div>
    </div>
</div>

<script class="commands"><![CDATA[


//
//  jGoogle for Parser 2
//
    
    

noun_type_googleService = new CmdUtils.NounType( "ServiceName", ["web", "ウェブ", "news" ,"ニュース", "image", "画像", "picasa", "map", "video", "動画"] );

noun_type_setAnim = new CmdUtils.NounType("boolean", ["true", "false"]);

CmdUtils.CreateCommand({
    names: ["jgoogle" , "ググる", "ぐぐる"],
    description: "Google.co.jp で検索します (for Parser 2)",
    arguments: [    {role: 'object', nountype: noun_arb_text, label: 'keyword'},
                    {role: 'instrument', nountype: noun_type_googleService, label: 'service'},
                    {role: 'modifier', nountype: ["animon", "animoff"] }],
    icon: "http://www.google.co.jp/favicon.ico",
    homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
    author: {name: "hokunarin", email: "hokunarin@gmail.com"},
    license: "MPL",
    
    preview: function( previewBlock, args ) {
        
        var setAnim = args.modifier.text || "";
        if(setAnim!=""){
            return;
        }
        
        var prefObj = Application.prefs.get("extensions.hokunarin.jgoogle.animation");
        var ANIM = true;
        if(prefObj!=null){
            ANIM = eval(prefObj.value);
        }
        
        var ubiquityVersion = Application.prefs.get("extensions.ubiquity.lastversion").value;
        
        var googleApiKey = "ABQIAAAAoVcPMDe-M1POPHO05xSD7xRhgaXi6XXdWOQWcfAzmL2fWIokvhSQIj1Pmpezo4LhU0qRyrhG_R8Xlg";
        
        var searchText = jQuery.trim(args.object.text || "");
        var serviceText = args.instrument.text || "web";
        
        if(serviceText=="動画"){
            serviceText = "video";
        }else if(serviceText=="画像"){
            serviceText = "image";
        }else if(serviceText=="ウェブ"){
            serviceText = "web";
        }else if(serviceText=="ニュース"){
            serviceText="news";
        }
        
        
        
        if(searchText.length < 1) {
            var previewStr = "Google " + serviceText + " を検索します<br/><br/>";
            previewStr += "<small>「キーワード」を検索する場合<br/>";
            previewStr += "<strong> キーワードをググる<br/><br/>";
            previewStr += " キーワードをニュースでググる<br/>";
            previewStr += " キーワードを画像でググる<br/>";
            previewStr += " キーワードを動画でググる<br/>";
            previewStr += " キーワードをpicasaでググる</strong><br/><br/>";
            previewStr += "「〜で」には web, ウェブ, news, ニュース, image, 画像, video, 動画, picasa を指定できます。<br/>";
            previewStr += "「〜で」を指定すると、それぞれ ニュース検索、画像検索、動画検索、Picasa検索を行います。<br/><br/>";
            previewStr += "その他の使い方<br/>";
            previewStr += "<strong> jgoogle キーワード<br/>";
            previewStr += "jgoogle キーワード 動画で</strong><br/>";
            previewStr += "など<br/><br/>";
            previewStr += "プレビューのアニメーションを止めるときは<br/>";
            previewStr += " <strong>jgoogle animoffの</strong><br/>";
            previewStr += "プレビューでアニメーションさせるときは<br/>";
            previewStr += " <strong>jgoogle animonの</strong><br/>";
            previewStr += "変な感じですが、「の」まで入力してください。<br/>";
            
            previewBlock.innerHTML = previewStr;
            return;
        }
        
        var previewTemplate = "<b>${query}</b> を Google ${service} で検索します...";
        var previewData = {query: searchText, service: serviceText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        jQuery(previewBlock).append('<div style="position:absolute;top:40%;left:40%;width:100px;height:50px;" id="progressimage"><img src="http://ubiquity-commands-ja-nora.googlecode.com/files/image_7990.gif" /></div>').find("#progressimage").hide().fadeIn(2000);
        
        
        if(serviceText == "news"){
            renderNews(0);
        }else if(serviceText=="web" || serviceText == ""){
            renderWeb(0);
        }else if(serviceText=="image"){
            renderImage(0);
        }else if(serviceText=="video"){
            renderVideo(0);
        }else if(serviceText=="picasa"){
            renderPicasa(0);
        }
        
        
        function renderNews(pageDiff){
            
            var page = eval(jQuery("#page",previewBlock).text());
            if(page>0){
                page = page - 1 + pageDiff;
            }else{
                page = 0;
            }
            
            if(ANIM){
                slideOut(jQuery(".item",previewBlock), pageDiff);
            }
            
            CmdUtils.previewAjax(previewBlock, {
                type: "GET",
                url: "http://news.google.com/news/search?ned=jp&hl=ja&q=" + encodeURIComponent(searchText) + "&start=" + ( page * 5 ) + "&key=" + googleApiKey ,
                dataType: "html",

                error: function() {
                    previewBlock.innerHTML = "Error searching Google news.";
                },

                success: function(responseData) {

                    responseData = jQuery(responseData);
                    var items = [];
                    var i = 0;
                    var resultsstats = responseData.find(".results-stats").text();
                    
                    responseData.find(".headline-story").slice(0,5).each(function(){
                        
                        var resultList = jQuery(this);
                        
                        var title = resultList.find(".title").text();
                        var url = resultList.find(".title a").attr("href");
                        var description = resultList.find(".snippet").html();
                        var sourcemedia = resultList.find(".sub-title").text();
                        
                        var jQphoto = resultList.find(".thumbnail");
                        
                        jQphoto.find("img").attr( "height", eval(jQphoto.find("img").attr("height")) * 0.7  );
                        jQphoto.find("img").attr( "width", eval(jQphoto.find("img").attr("width")) * 0.7  );
                        jQphoto.find("img").css({border:"1px solid gray"});
                        
                        var photo = jQphoto.html();
                        
                        var key = ++i;
                        
                        var item = {key : key,
                                    title : title,
                                    url : url,
                                    description : description,
                                    sourcemedia : sourcemedia,
                                    photo : photo
                                    };
                        
                        items.push(item);
                        
                    });
                    
                    var previewData = {
                                          query : searchText,
                                          resultsstats : resultsstats,
                                          page : page + 1,
                                          items : items
                                        };
                    
                    previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jgoogle-news", feed.dom).html(), previewData);
                    
                    
                    if(page>0){
                        jQuery("#prev", previewBlock).show();
                        jQuery("#prev", previewBlock).click(function(){
                            renderNews( -1 );
                            jQuery(this).unbind();
                        });
                    }else{
                        jQuery("#prev", previewBlock).hide();
                    }
                    
                    if(items.length >= 5){
                        jQuery("#next", previewBlock).show();
                        jQuery("#next", previewBlock).click(function(){
                            renderNews( 1 );
                            jQuery(this).unbind();
                        });
                    }else{
                        jQuery("#next", previewBlock).hide();
                    }
                    
                    
                    jQuery(".itemhref", previewBlock).each(function(){
                        jQuery(this).one("mousedown", function(evt){
                            
                            if(evt && ( evt.which == 3 || evt.button == 2)){
                                var doc = context.focusedWindow.document;
                                var focused = context.focusedElement;
                                
                                var parent = jQuery(this).parents(".item");
                                
                                if (doc.designMode == "on"){
                                    jQuery(".accesskey", parent).hide();
                                    jQuery(".itemtitle", parent).css({"background":"#cddeff", "width":"460px"});
                                    jQuery(".itemdesc", parent).css({"background":"white", "width":"460px"});
                                    jQuery(parent).append('<div style="clear:both;"> </div> <br/>');
                                    jQuery(parent).before('<div> </div> <br/>');
                                    
                                    doc.execCommand("insertHTML", false, jQuery(parent).html() );
                                    closeUbiquity();
                                    
                                }else if (focused != null && ((focused.type == "textarea") || (focused.type == "text"))){
                                    var parent = jQuery(this).parents(".item");
                                    CmdUtils.setSelection(jQuery(".itemtitletext", parent).text() + "\n" + jQuery(".itemhref", parent).attr("href") + "\n");
                                    closeUbiquity();
                                    
                                }else{
                                    displayMessage("編集可能な部分に対して挿入出来ます。");
                                }
                            }
                            
                            evt.stopPropagation();
                            //evt.preventDefault();
                            //return false;
                        });
                    });
                    
                    
                    if(ANIM){
                        slideIn(jQuery(".item", previewBlock), pageDiff);
                    }
                    
                } //success
              
            }); //previewAjax
            
        }//renderNews
        
        
        
        function renderWeb(pageDiff){
            
            var page = eval(jQuery("#page",previewBlock).text());
            if(page>0){
                page = page - 1 + pageDiff;
            }else{
                page = 0;
            }
            
            
            if(ANIM){
                slideOut(jQuery(".item",previewBlock), pageDiff);
            }
            
            
            CmdUtils.previewAjax(previewBlock, {
                type: "GET",
                url: "http://ajax.googleapis.com/ajax/services/search/web",
                data:   {
                            v : "1.0",
                            rsz : "large",
                            hl : "ja",
                            lr : "lang_ja",
                            q : searchText,
                            start : (page * 5),
                            key : googleApiKey
                        },
                dataType: "json",

                error: function() {
                    previewBlock.innerHTML = "Error searching Google news.";
                },

                success: function(json) {
                    
                    var items = [];
                    var i = 0;
                    
                    jQuery.each(json.responseData.results.slice(0,5), function(){
                        
                        var title = this.title;
                        //var url = this.url;
                        var url = this.unescapedUrl;
                        var description = this.content.substring(0, 220) + "</b></b></b>";
                        var visibleUrl = this.visibleUrl;
                        var cacheUrl = this.cacheUrl;
                        
                        var key = ++i;
                        
                        var item = {key : key,
                                    title : title,
                                    url : url,
                                    description : description,
                                    visibleUrl : visibleUrl,
                                    cacheUrl: cacheUrl
                                    };
                        
                        items.push(item);
                        
                    });
                    
                    var previewData = {
                                          query : searchText,
                                          page : page + 1,
                                          items : items
                                        };
                    
                    previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jgoogle-web", feed.dom).html(), previewData);
                    
                    
                    if(page>0){
                        jQuery("#prev", previewBlock).show();
                        jQuery("#prev", previewBlock).one("click", function(){
                            renderWeb( -1 );
                        });
                    }else{
                        jQuery("#prev", previewBlock).hide();
                    }
                    
                    if(items.length >= 5 && page < 11 ){
                        jQuery("#next", previewBlock).show();
                        jQuery("#next", previewBlock).one("click", function(){
                            renderWeb( 1 );
                        });
                    }else{
                        jQuery("#next", previewBlock).hide();
                    }
                    
                    
                    jQuery(".itemhref", previewBlock).each(function(){
                        jQuery(this).one("mousedown", function(evt){
                            
                            if(evt && ( evt.which == 3 || evt.button == 2)){
                                var doc = context.focusedWindow.document;
                                var focused = context.focusedElement;
                                
                                var parent = jQuery(this).parents(".item");
                                
                                if (doc.designMode == "on"){
                                    jQuery(".accesskey", parent).hide();
                                    jQuery(".itemtitle", parent).css({"background":"#cdf", "width":"460px"});
                                    jQuery(".itemdesc", parent).width(460);
                                    jQuery(parent).append('<div style="clear:both;"> </div> <br/>');
                                    jQuery(parent).before('<div> </div> <br/>');
                                    
                                    doc.execCommand("insertHTML", false, jQuery(parent).html() );
                                    closeUbiquity();
                                    
                                }else if (focused != null && ((focused.type == "textarea") || (focused.type == "text"))){
                                    var parent = jQuery(this).parents(".item");
                                    CmdUtils.setSelection(jQuery(".itemtitletext", parent).text() + "\n" + jQuery(".itemhref", parent).attr("href") + "\n");
                                    closeUbiquity();
                                    
                                }else{
                                    displayMessage("編集可能な部分に対して挿入出来ます。");
                                }
                            }
                            
                            evt.stopPropagation();
                            //evt.preventDefault();
                            //return false;
                        });
                    });
                    
                    
                    if(ANIM){
                        slideIn(jQuery(".item", previewBlock), pageDiff);
                    }
                    
                    
                } //success
              
            }); //previewAjax
            
        }//renderWeb
        
        
        function renderImage(pageDiff){
            
            var page = eval(jQuery("#page",previewBlock).text());
            if(page>0){
                page = page - 1 + pageDiff;
            }else{
                page = 0;
            }
            
            
            if(ANIM){
                slideOut(jQuery(".item",previewBlock), pageDiff);
            }
            
            CmdUtils.previewAjax(previewBlock, {
                type: "GET", 
                url: "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&hl=ja&lr=lang_ja&q=" + encodeURIComponent(searchText) + "&start=" + ( page * 7 ) + "&key=" + googleApiKey, 
                dataType: "json",
                
                error: function() {
                    previewBlock.innerHTML = "Error searching Google image.";
                },

                success: function(json) {
                    
                    var items = [];
                    var i = 0;
                    var maxWidth = 100;
                    
                    jQuery.each(json.responseData.results.slice(0,7), function(){
                        
                        var title = this.title;
                        var escapedurl = this.url;
                        var url = this.unescapedUrl;
                        var snippet = this.content;
                        var visibleurl = this.visibleUrl;
                        var tburl = this.tbUrl;
                        var thumbh = this.tbHeight;
                        var thumbw = this.tbWidth;
                        var refurl = this.originalContextUrl;
                        var width = this.width;
                        var height = this.height;
                        
                        var key = ++i;
                        
                        if(thumbw>maxWidth){
                            thumbh = thumbh * (maxWidth/thumbw);
                            thumbw = maxWidth;
                        }
                        
                        var item = {key : key,
                                    title : title,
                                    escapedurl: escapedurl,
                                    url : url,
                                    snippet : snippet,
                                    visibleurl : visibleurl,
                                    tburl : tburl,
                                    thumbh: thumbh,
                                    thumbw : thumbw,
                                    refurl : refurl,
                                    width : width,
                                    height : height
                                    };
                        
                        items.push(item);
                        
                    });
                    
                    var previewData = {
                                          query : searchText,
                                          page : page + 1,
                                          items : items
                                        };
                    
                    previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jgoogle-image", feed.dom).html(), previewData);
                    
                    
                    if(page>0){
                        jQuery("#prev", previewBlock).show();
                        jQuery("#prev", previewBlock).one("click", function(){
                            renderImage( -1 );
                        });
                    }else{
                        jQuery("#prev", previewBlock).hide();
                    }
                    
                    if(items.length >= 5 && page < 8 ){
                        jQuery("#next", previewBlock).show();
                        jQuery("#next", previewBlock).one("click", function(){
                            renderImage( 1 );
                        });
                    }else{
                        jQuery("#next", previewBlock).hide();
                    }
                    
                    
                    
                    jQuery(".itemhref", previewBlock).each(function(){
                        jQuery(this).one("mousedown", function(evt){
                            
                            if(evt && ( evt.which == 3 || evt.button == 2)){
                                var doc = context.focusedWindow.document;
                                var focused = context.focusedElement;
                                
                                var parent = jQuery(this).parents(".item");
                                
                                if (doc.designMode == "on"){
                                    jQuery(".accesskey", parent).hide();
                                    jQuery(".itemthumb", parent).css({"border":"0px"});
                                    jQuery(".itemthumbframe", parent).css({"border":"0px"});
                                    jQuery(parent).append('<div style="clear:both;"> </div> <br/>');
                                    jQuery(parent).before('<div> </div> <br/>');
                                    
                                    doc.execCommand("insertHTML", false, jQuery(parent).html() );
                                    closeUbiquity();
                                    
                                }else if (focused != null && ((focused.type == "textarea") || (focused.type == "text"))){
                                    var parent = jQuery(this).parents(".item");
                                    CmdUtils.setSelection( "Google 画像検索の結果：" + jQuery(".itemtitletext", parent).text() + "\n" + jQuery(".itemhref", parent).attr("href") + "\n" );
                                    closeUbiquity();
                                    
                                }else{
                                    displayMessage("編集可能な部分に対して挿入出来ます。");
                                }
                            }
                            
                            evt.stopPropagation();
                            //evt.preventDefault();
                            //return false;
                        });
                    });
                    
                    
                    if(ANIM){
                        slideIn(jQuery(".item", previewBlock), pageDiff);
                    }
                    
                    
                } //success
              
            }); //previewAjax
            
        }//renderImage
        
        
        
        function renderVideo(pageDiff){
            
            var page = eval(jQuery("#page",previewBlock).text());
            if(page>0){
                page = page - 1 + pageDiff;
            }else{
                page = 0;
            }
            
            
            if(ANIM){
                slideOut(jQuery(".item",previewBlock), pageDiff);
            }
            
            CmdUtils.previewAjax(previewBlock, {
                type: "GET", 
                url: "http://ajax.googleapis.com/ajax/services/search/video?v=1.0&rsz=large&hl=ja&lr=lang_ja&q=" + encodeURIComponent(searchText) + "&start=" + ( page * 7 ) + "&key=" + googleApiKey, 
                dataType: "json",
                
                error: function() {
                    previewBlock.innerHTML = "Error searching Google video.";
                },

                success: function(json) {
                    
                    var items = [];
                    var i = 0;
                    var maxWidth = 100;
                    
                    jQuery.each(json.responseData.results.slice(0,7), function(){
                        
                        var title = this.title;
                        var escapedurl = this.url;
                        //var url = this.unescapedUrl;
                        var url = this.url;
                        //var snippet = this.content;
                        var snippet = this.content.slice(0,35)+"...";
                        //var visibleurl = this.visibleUrl;
                        var visibleurl = this.publisher;
                        var tburl = this.tbUrl;
                        var thumbh = this.tbHeight;
                        var thumbw = this.tbWidth;
                        //var refurl = this.originalContextUrl;
                        var refurl = this.url;
                        var width = this.width;
                        var height = this.height;
                        
                        var key = ++i;
                        
                        if(thumbw>maxWidth){
                            thumbh = thumbh * (maxWidth/thumbw);
                            thumbw = maxWidth;
                        }
                        
                        var item = {key : key,
                                    title : title,
                                    escapedurl: escapedurl,
                                    url : url,
                                    snippet : snippet,
                                    visibleurl : visibleurl,
                                    tburl : tburl,
                                    thumbh: thumbh,
                                    thumbw : thumbw,
                                    refurl : refurl,
                                    width : width,
                                    height : height
                                    };
                        
                        items.push(item);
                        
                    });
                    
                    var previewData = {
                                          query : searchText,
                                          page : page + 1,
                                          items : items
                                        };
                    
                    previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jgoogle-video", feed.dom).html(), previewData);
                    
                    
                    if(page>0){
                        jQuery("#prev", previewBlock).show();
                        jQuery("#prev", previewBlock).one("click", function(){
                            renderVideo( -1 );
                        });
                    }else{
                        jQuery("#prev", previewBlock).hide();
                    }
                    
                    if(items.length >= 5 && page < 8 ){
                        jQuery("#next", previewBlock).show();
                        jQuery("#next", previewBlock).one("click", function(){
                            renderVideo( 1 );
                        });
                    }else{
                        jQuery("#next", previewBlock).hide();
                    }
                    
                    
                    
                    jQuery(".itemhref", previewBlock).each(function(){
                        jQuery(this).one("mousedown", function(evt){
                            
                            if(evt && ( evt.which == 3 || evt.button == 2)){
                                var doc = context.focusedWindow.document;
                                var focused = context.focusedElement;
                                
                                var parent = jQuery(this).parents(".item");
                                
                                if (doc.designMode == "on"){
                                    jQuery(".accesskey", parent).hide();
                                    jQuery(".itemthumb", parent).css({"border":"0px"});
                                    jQuery(".itemthumbframe", parent).css({"border":"0px"});
                                    jQuery(parent).append('<div style="clear:both;"> </div> <br/>');
                                    jQuery(parent).before('<div> </div> <br/>');
                                    
                                    doc.execCommand("insertHTML", false, jQuery(parent).html() );
                                    closeUbiquity();
                                    
                                }else if (focused != null && ((focused.type == "textarea") || (focused.type == "text"))){
                                    var parent = jQuery(this).parents(".item");
                                    CmdUtils.setSelection( "Google 動画検索の結果：" + jQuery(".itemtitletext", parent).text() + "\n" + jQuery(".itemhref", parent).attr("href") + "\n" );
                                    closeUbiquity();
                                    
                                }else{
                                    displayMessage("編集可能な部分に対して挿入出来ます。");
                                }
                            }
                            
                            evt.stopPropagation();
                            //evt.preventDefault();
                            //return false;
                        });
                    });
                    
                    
                    if(ANIM){
                        slideIn(jQuery(".item", previewBlock), pageDiff);
                    }
                    
                    
                } //success
              
            }); //previewAjax
            
        }//renderVideo
        
        
        
        function renderPicasa(pageDiff){
            
            var itemsPerPage = 7;
            
            var page = eval(jQuery("#page",previewBlock).text());
            if(page>0){
                page = page - 1 + pageDiff;
            }else{
                page = 0;
            }
            
            
            if(ANIM){
                slideOut(jQuery(".item",previewBlock), pageDiff);
            }
            
            var requestUrl = "http://picasaweb.google.com/data/feed/tiny/all?alt=jsonm&kind=photo&access=public&start-index=" + ( page * 7 + 1) + "&max-results=" + itemsPerPage + "&q=" + encodeURI(searchText);
            
            CmdUtils.previewAjax(previewBlock, {
                type: "GET", 
                url: requestUrl, 
                dataType: "json",
                
                error: function() {
                    previewBlock.innerHTML = "Error searching Picasa.";
                },
                
                success: function(json) {
                    
                    var items = [];
                    var i = 0;
                    var maxWidth = 94; // 72, 94, 110, 128, 160, ...
                    
                    var totalResults = json.feed.totalResults;
                    
                    var lastItemNumInPage = ( (page + 1) * 7 > totalResults) ? totalResults : (page + 1) * 7;
                    
                    if(totalResults==0){
                        previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jgoogle-picasa", feed.dom).html(), {query:searchText, page:0, items:null, totalResults:totalResults, lastItemNumInPage:0});
                        jQuery("#resultsscope", previewBlock).hide();
                        jQuery("#prev", previewBlock).hide();
                        jQuery("#next", previewBlock).hide();
                    }
                    
                    jQuery.each(json.feed.entry.slice(0,itemsPerPage), function(){
                        
                        //var title = this.media.description;
                        var title = this.albumTitle;
                        var snippet = this.snippet;
                        var author = this.author[0].name;
                        var authorUrl = this.author[0].uri;
                        var imageUrl = this.media.content[0].url;
                        
                        var tburl = imageUrl.replace(/(.*)\//, "$1/s" + maxWidth + "/");
                        
                        var thumbh = 0;
                        var thumbw = 0;
                        
                        if( this.media.content[0].height > this.media.content[0].width){
                            thumbh = maxWidth;
                            thumbw = this.media.content[0].width * ( maxWidth / this.media.content[0].height );
                        }else{
                            thumbw = maxWidth;
                            thumbh = this.media.content[0].height * ( maxWidth / this.media.content[0].width );
                        }
                        
                        var url = "";
                        for(var j = 0 ; j < this.link.length; j++){
                            if(this.link[j].rel=="alternate"){
                                url = this.link[j].href;
                            }
                        }
                        
                        var key = ++i;
                        
                        var item = {key : key,
                                    title : title,
                                    url : url,
                                    snippet : snippet,
                                    author : author,
                                    authorUrl : authorUrl,
                                    tburl : tburl,
                                    thumbh: thumbh,
                                    thumbw : thumbw
                                    };
                        
                        items.push(item);
                        
                    });
                    
                    var previewData = {
                                          query : searchText,
                                          page : page + 1,
                                          lastItemNumInPage : lastItemNumInPage,
                                          items : items,
                                          totalResults : totalResults
                                        };
                    
                    previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jgoogle-picasa", feed.dom).html(), previewData);
                    
                    
                    if(page>0){
                        jQuery("#prev", previewBlock).show();
                        jQuery("#prev", previewBlock).one("click", function(){
                            renderPicasa( -1 );
                        });
                    }else{
                        jQuery("#prev", previewBlock).hide();
                    }
                    
                    if(items.length >= itemsPerPage && ((page + 1) * itemsPerPage) < totalResults ){
                        jQuery("#next", previewBlock).show();
                        jQuery("#next", previewBlock).one("click", function(){
                            renderPicasa( 1 );
                        });
                    }else{
                        jQuery("#next", previewBlock).hide();
                    }
                    
                    
                    jQuery(".itemhref", previewBlock).each(function(){
                        jQuery(this).one("mousedown", function(evt){
                            
                            if(evt && ( evt.which == 3 || evt.button == 2)){
                                var doc = context.focusedWindow.document;
                                var focused = context.focusedElement;
                                
                                var parent = jQuery(this).parents(".item");
                                
                                if (doc.designMode == "on"){
                                    jQuery(".accesskey", parent).hide();
                                    jQuery(".itemthumb", parent).css({"border":"0px"});
                                    jQuery(".itemthumbframe", parent).css({"border":"0px"});
                                    jQuery(parent).append('<div style="clear:both;"> </div> <br/>');
                                    jQuery(parent).before('<div> </div> <br/>');
                                    
                                    doc.execCommand("insertHTML", false, jQuery(parent).html() );
                                    closeUbiquity();
                                    
                                }else if (focused != null && ((focused.type == "textarea") || (focused.type == "text"))){
                                    var parent = jQuery(this).parents(".item");
                                    CmdUtils.setSelection( "Picasa 検索の結果：" + jQuery(".itemtitletext", parent).text() + "\n" + jQuery(".itemhref", parent).attr("href") + "\n" );
                                    closeUbiquity();
                                    
                                }else{
                                    displayMessage("編集可能な部分に対して挿入出来ます。");
                                }
                            }
                            
                            evt.stopPropagation();
                            //evt.preventDefault();
                            //return false;
                        });
                    });
                    
                    //for Ubiquity 0.1.x / 0.5  difference
                    if (ubiquityVersion.indexOf("0.1.") > -1){
                        jQuery("#prev", previewBlock).attr({href:""});
                        jQuery("#next", previewBlock).attr({href:""});
                    }else{
                        jQuery("#prev", previewBlock).removeAttr("href");
                        jQuery("#next", previewBlock).removeAttr("href");
                    }
                    
                    //for Ubiquity 0.5pre
                    /*
                    jQuery("a", previewBlock).each(function(){
                        if( jQuery(this).attr("href") != undefined && jQuery(this).attr("href").length > 0 ){
                            jQuery(this).one("click", function(evt){
                                evt.preventDefault();
                                evt.stopPropagation();
                                
                                Utils.focusUrlInBrowser( jQuery(this).attr("href") );
                            });
                        }
                        
                    });
                    */
                    
                    
                    if(ANIM){
                        slideIn(jQuery(".item", previewBlock), pageDiff);
                    }
                    
                    
                } //success
              
            }); //previewAjax
            
        }//renderPicasa
        
        
        
        
        function closeUbiquity(){
            window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                    .getInterface(Components.interfaces.nsIWebNavigation)
                    .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                    .rootTreeItem
                    .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                    .getInterface(Components.interfaces.nsIDOMWindow)
                    .gUbiquity
                    .closeWindow();
        }
        
        
        function slideOut(items, pageDiff){
            var i=0;
            jQuery(items.get().reverse()).each(function(){
                var itemBlock = jQuery(this);
                var iw = itemBlock.width();
                var ih = itemBlock.height();
                var it = itemBlock.position().top;
                itemBlock.css({ "width": iw,
                                "height":ih,
                                "top":it,
                                "position":"absolute",
                                "opacity":"1"});
                itemBlock.animate( {"left": ((pageDiff>0)?"-":"+") + "=500px", "opacity":"0"}, 500 - pageDiff*(80 * i - 200) );
                i++;
            });
            
            jQuery(items).parent().append('<div style="position:absolute;top:40%;left:40%;width:100px;height:50px;" id="progressimage"><img src="http://ubiquity-commands-ja-nora.googlecode.com/files/image_7990.gif" /></div>').find("#progressimage").hide().fadeIn(2000);
        }
        
        function slideIn(items, pageDiff){
            var i = 0;
            jQuery(items.get().reverse()).each(function(){
                var itemBlock = jQuery(this);
                var iw = itemBlock.width();
                var ih = itemBlock.height();
                var it = itemBlock.position().top;
                var il = itemBlock.position().left;
                itemBlock.css({ "width":iw,
                                "height":ih,
                                "top": it,
                                "left": ( eval( (pageDiff>=0?"+":"-") + "1") * 500 + il) + "px",
                                "position": "absolute",
                                "opacity":"0"});
                itemBlock.animate({"left":(pageDiff>=0?"-":"+") + "=500px", "opacity":"1"}, 500 - ((pageDiff==0)?1:pageDiff)*( i * 80 - 200 ) );
                i++;
            });
        }
        
        
    },

    execute: function(args) {
        
        
        var setAnim = args.modifier.text;
        if(setAnim){
            if(setAnim=="animon"){
                Application.prefs.setValue("extensions.hokunarin.jgoogle.animation", true);
                displayMessage("アニメーションが有効になりました。");
                return;
            }else if(setAnim=="animoff"){
                Application.prefs.setValue("extensions.hokunarin.jgoogle.animation", false);
                displayMessage("アニメーションが無効になりました。");
                return;
            }
        }
        
        
        var inWhat = args.instrument.text || "web";
        
        if(inWhat=="動画"){
            inWhat = "video";
        }else if(inWhat=="画像"){
            inWhat = "image";
        }else if(inWhat=="ウェブ"){
            inWhat = "web";
        }else if(inWhat=="ニュース"){
            inWhat="news";
        }
        
        var enctext = encodeURIComponent(args.object.text);
        if(inWhat=="news"){
            Utils.openUrlInBrowser( "http://news.google.com/news/search?ned=jp&hl=ja&q=" + enctext );
        }else if(inWhat=="web" || inWhat==""){
            Utils.openUrlInBrowser("http://www.google.com/search?ned=jp&hl=ja&q=" + enctext);
        }else if(inWhat=="image"){
            Utils.openUrlInBrowser("http://images.google.co.jp/images?hl=ja&q=" + enctext);
        }else if(inWhat=="video"){
            Utils.openUrlInBrowser("http://video.google.co.jp/videosearch?aq=f&q=" + enctext);
        }else if(inWhat=="picasa"){
            Utils.openUrlInBrowser("http://picasaweb.google.com/lh/view?psc=G&q=" + enctext);
        }
        
        
    }
});



]]></script>
</body>
</html>
